var t = require("../../@babel/runtime/helpers/interopRequireDefault").default, e = t(require("../../kta/index")), a = t(require("../../api/api_YQYL.js")), i = t(require("../../api/auth")), o = require("../../config/Links"), n = require("../../utils/YQYL"), s = [ null, "uncomplete", "complete", "failure" ], c = 1, l = getApp();

e.default.Page({
    data: {
        height: 1100,
        activity_info: {},
        check_id_card: !1,
        shareUrl: "",
        imgBaseUrl: o.imageBaseUrl.YQYL_new,
        imgBaseUrl2: o.imageBaseUrl.YQYL2,
        tabIndex: "1",
        invite_record_list: [],
        showList: [],
        succeed_count: 0,
        able_to_receive: !1,
        red_packet_daily_limit: !1,
        showModal: !1,
        modal: !1,
        cancelText: "",
        modalText: "",
        time: 0,
        showPoster: !1,
        poster: null,
        postUtil: {
            handleSharePoster: function() {}
        },
        showGuide: !1,
        showToast: !1,
        isFinish: !1
    },
    onShareAppMessage: function() {
        return (0, n.handleShare)(this, "record");
    },
    onLoad: function(t) {
        var e = this;
        wx.getSystemInfo({
            success: function(t) {
                e.setData({
                    height: t.windowHeight - 130
                });
            }
        }), (0, n.initPage)(this, t).then(function() {
            Promise.all([ "uncomplete", "complete", "failure" ].map(function(t) {
                return a.default.getRecordList(1, t);
            })).then(function(t) {
                t.map(function(t) {
                    return t.invite_info.invite_record_list;
                }).flat().length;
            });
        });
    },
    onShow: function() {
        this.fetchList();
    },
    fetchList: function() {
        var t = this;
        wx.showLoading({
            title: "加载中"
        }), a.default.getRecordList(c, s[this.data.tabIndex]).then(function(e) {
            var a = e.invite_info, i = a.achieve_goal_reward, o = a.invite_record_list, n = a.check_id_card, s = a.red_packet_daily_limit;
            o.forEach(function(t) {
                t.order_time > 16524234e5 ? t.type = "28" : t.type = "18";
            });
            var l = i.succeed_count, r = l % 5;
            l = 0 !== l && 0 === r ? 5 : r, t.setData({
                red_packet_daily_limit: s,
                check_id_card: n,
                invite_record_list: o,
                succeed_count: l,
                able_to_receive: i.able_to_receive,
                showList: o.slice(0, 10 * c)
            }), wx.hideLoading();
        });
    },
    loadMore: function() {
        10 * c < this.data.invite_record_list.length && (c++, this.setData({
            showList: this.data.invite_record_list.slice(0, 10 * c)
        }));
    },
    onChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    changeTab: function(t) {
        var e = this, a = t.currentTarget.dataset.index;
        c = 1, this.setData({
            tabIndex: a
        }, function() {
            e.fetchList();
        });
    },
    handlePoster: function() {
        if (this.data.isFinish) return wx.showToast({
            title: "活动已结束，当前无法邀好友领奖励，更多优惠活动情关注“王卡助手”微信公众号。",
            icon: "none",
            duration: 2500
        }), !1;
        this.data.poster ? this.setData({
            showPoster: !0
        }) : this.data.postUtil.handleSharePoster("record");
    },
    handleShareText: function() {
        var t = this;
        if (this.data.isFinish) return wx.showToast({
            title: "活动已结束，当前无法邀好友领奖励，更多优惠活动情关注“王卡助手”微信公众号。",
            icon: "none",
            duration: 2500
        }), !1;
        this.setData({
            showToast: !0
        }), setTimeout(function() {
            t.setData({
                showToast: !1
            });
        }, 3e3), wx.setClipboardData({
            data: this.data.activity_info.invite_short_url
        });
    },
    showModal: function(t) {
        var e = this, i = t.currentTarget.dataset.type;
        if ("order" === i) wx.showToast({
            title: "好友未完成首充，暂不可领取红包！",
            icon: "none",
            duration: 2e3
        }); else if ("active" === i) wx.showToast({
            title: "好友未完成首充，暂不可领取红包！",
            icon: "none",
            duration: 2e3
        }); else if ("illegal" === i) wx.showModal({
            content: "订单信息发生变更，无法领取红包，敬请谅解",
            showCancel: !1,
            confirmText: "确定"
        }); else if ("illegal2" === i) wx.showModal({
            content: "微信红包发放后的24小时内未领取。已超时退回",
            showCancel: !1,
            confirmText: "确定"
        }); else if (this.data.red_packet_daily_limit) wx.showModal({
            content: "单用户单日领取红包个数限额10个，请于次日领取",
            showCancel: !1,
            confirmText: "确定"
        }); else {
            if ("charge" === i) {
                var o = t.currentTarget.dataset.seq;
                this.checkValid() && a.default.getHongBao(o).then(function() {
                    wx.showModal({
                        content: "红包将通过“王卡助手”微信公众号发放，请您留意公众号消息",
                        showCancel: !1,
                        confirmText: "知道啦"
                    }), e.fetchList();
                }).catch(function(t) {
                    wx.showModal({
                        content: t.msg,
                        showCancel: !1,
                        confirmText: "确定"
                    });
                });
            }
            "all" === i && this.checkValid() && a.default.getHongBao().then(function() {
                wx.showModal({
                    content: "红包将通过“王卡助手”微信公众号发放，请您留意公众号消息",
                    showCancel: !1,
                    confirmText: "知道啦"
                }), e.fetchList();
            }).catch(function(t) {
                e.toRegisterPage(), wx.showModal({
                    content: t.msg,
                    showCancel: !1,
                    confirmText: "确定"
                });
            }), "100" === i && (this.data.able_to_receive ? this.checkValid() && a.default.get100yuan().then(function() {
                e.fetchList(), wx.showModal({
                    content: "红包将通过“王卡助手”微信公众号发放，请您留意公众号消息。",
                    showCancel: !1,
                    confirmText: "确定"
                });
            }).catch(function() {
                wx.showModal({
                    content: "微信异常，红包发放失败",
                    showCancel: !1,
                    confirmText: "确定"
                });
            }) : this.setData({
                modal: !0,
                modalText: "邀请成功人数未满5人，无法领取100元达量奖励，继续努力!",
                modalType: "invite"
            }));
        }
    },
    checkValid: function() {
        return !!this.data.check_id_card || (l.globalData.phone ? wx.navigateTo({
            url: "/pages/YQYL_register/index?adtag=" + l.globalData.aucChannel
        }) : this.setData({
            modal: !0,
            modalText: "手机号码获取失败，无法领取红包!",
            modalType: "phone"
        }), !1);
    },
    getPhoneNumber: function(t) {
        this.setData({
            modal: !1,
            modalText: "",
            modalType: ""
        }), i.default.auth({
            encryptedData: t.detail.encryptedData,
            iv: t.detail.iv,
            source: 2
        }).then(function(t) {
            l.globalData.phone = t.data.phone, wx.navigateTo({
                url: "/pages/YQYL_register/index?channel=".concat(l.globalData.aucChannel, "&adtag=").concat(l.globalData.aucChannel)
            });
        });
    },
    showGuideModal: function() {
        this.setData({
            showGuide: !0
        });
    },
    closeModal: function() {
        this.setData({
            modal: !1,
            showModal: !1,
            showGuide: !1,
            modalText: ""
        });
    },
    closePoster: function() {
        this.setData({
            showPoster: !1
        });
    },
    toOldRecordPage: function() {
        wx.navigateTo({
            url: "/pages/webview/index?url=".concat(encodeURIComponent("https://txwk.10010.com/KCard/wxCommon/goto?state=WZJH_RECOMMEND_URL"))
        });
    },
    toQuestionPage: function() {
        wx.navigateTo({
            url: "/pages/YQYL_question/index"
        });
    },
    toSpreadPage: function() {
        wx.navigateTo({
            url: "/pages/YQYL_homePageSpread/index?channel=01-0379-a5ar-a6ln&adtag=01-0379-a5ar-a6ln"
        });
    },
    copyKeyword: function() {
        wx.setClipboardData({
            data: "我的历史邀请记录"
        }), this.closeModal();
    }
});